package org.restoran.service.parser.jackson;

import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.JsonProcessingException;
import org.codehaus.jackson.map.JsonSerializer;
import org.codehaus.jackson.map.SerializerProvider;
import org.restoran.model.ItemOrder;

import java.io.IOException;

/**
 * @author Snisar Bogdan.
 */
public class ItemOrderBeanSerializer extends JsonSerializer<ItemOrder> {

    @Override
    public void serialize(ItemOrder value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException {
        jgen.writeStartObject();
        jgen.writeFieldName("id");
        jgen.writeString(value.getPk().getItem().getId().toString());
        jgen.writeFieldName("count");
        jgen.writeString(value.getCount().toString());
        jgen.writeEndObject();
    }
}
